package com.copm.demonstrationsystem.controller.modulemanagefeatures;

import com.copm.demonstrationsystem.commons.response.ResponseStatus;
import com.copm.demonstrationsystem.commons.util.ControllerUtils;
import com.copm.demonstrationsystem.service.modulemanagefeatures.ModuleManageFeaturesService;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author chuyunfei
 * @date: 2018/4/15
 * @description: 模块定制功能的web控制层
 */
@RestController
@RequestMapping("/module")
@CrossOrigin
public class ModuleManageFeaturesController {

    //服务层对象
    private ModuleManageFeaturesService barService;

    @ApiOperation("获取全部的一级功能模块菜单")
    //请求参数
    @ApiImplicitParams({
            @ApiImplicitParam(name = "select",value = "是否对以及菜单进行筛选，如果是true：筛选，反之，默认不筛选"
                    ,dataType = "Boolean",paramType = "query",defaultValue = "false")
    })
    @RequestMapping(value = "/main",method = RequestMethod.GET)
    public ResponseStatus getMain(@RequestParam("select")Boolean select){

        return ControllerUtils.fillResponse(new ResponseStatus(),barService.getMain(select));
    }

    @ApiOperation("获取指定一级菜单的二级菜单")
    //请求参数
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "父级菜单的id，顶级菜单的父级菜单的id是0"
                    ,dataType = "Long",paramType = "path",required = true),
            @ApiImplicitParam(name = "select",value = "是否对以及菜单进行筛选，如果是true：筛选，反之，默认不筛选"
                    ,dataType = "Boolean",paramType = "query",defaultValue = "false")
    })
    @RequestMapping(value = "second/{id}",method = RequestMethod.GET)
    public ResponseStatus getSecond(@PathVariable("id")Long id,@RequestParam("select")Boolean select){

        return ControllerUtils.fillResponse(new ResponseStatus(),barService.getSecond(id, select));
    }

    @ApiOperation("设置菜单是否启用的接口")
    //请求参数
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "父级菜单的id，顶级菜单的父级菜单的id是0"
                    ,dataType = "Long",paramType = "path",required = true),
            @ApiImplicitParam(name = "enable",value = "设置该菜单的状态，true：启用，反之"
                    ,dataType = "Boolean",paramType = "query",required = true)
    })
    @RequestMapping(value = "enable/{id}",method = RequestMethod.PUT)
    public ResponseStatus setModuleEnable(@PathVariable("id")Long id,@RequestParam("enable")Boolean enable){

        return ControllerUtils.fillResponse(new ResponseStatus(),barService.setModuleEnable(id, enable));
    }

    @ApiOperation("修改菜单名称的接口")
    //请求参数
    @ApiImplicitParams({
            @ApiImplicitParam(name = "id",value = "父级菜单的id，顶级菜单的父级菜单的id是0"
                    ,dataType = "Long",paramType = "path",required = true),
            @ApiImplicitParam(name = "name",value = "菜单的新名字"
                    ,dataType = "String",paramType = "query",required = true)
    })
    @RequestMapping(value = "/name/{id}",method = RequestMethod.PUT)
    public ResponseStatus updateModuleName(@PathVariable("id")Long id,@RequestParam("name")String name){

        return ControllerUtils.fillResponse(new ResponseStatus(),barService.updateModuleName(id, name));
    }

    @Autowired
    public void setBarService(ModuleManageFeaturesService barService){
        this.barService = barService;
    }
}
